package com.lingxu.base.common.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Title: NumberUtils
 * @Package: com.lingxu.base.common.util
 * @Author: ysj闫世杰
 * @Email: 1105324813@qq.com
 * @Date: Created in 2021/8/10 11:49
 * @Description:
 * @Version: 1.0.0
 */
public class MoneyUtils {

    /**
     * @Author ysj闫世杰
     * @Description 万字单位并且保留一位小数
     * @Date 2021/8/10 13:42
     * @Param: money
     * @return java.lang.String
     **/
    public static String getMoneyText(BigDecimal money,int scale){
         BigDecimal defaultValue = new BigDecimal("10000");
        if(money == null){
            return null;
        }
        if(money.compareTo(defaultValue) < 0){
            return money + "";
        }
        //四舍五入指定保留小数位数
        BigDecimal divide = money.divide(defaultValue, scale,RoundingMode.HALF_UP);
        return divide + "";
    }

    public static void main(String[] args) {
        System.out.println(getMoneyText(new BigDecimal("1201000"),1));
    }
}
